﻿using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Description;

namespace AllMyMoney.WCFService
{
    public sealed class I18nAttribute : Attribute, IOperationBehavior
    {
        public string locale
        {
            get { return _locale; }
            set { _locale = value; }
        }

        public string timezone
        {
            get { return _timezone; }
            set { _timezone = value; }
        }

        //
        // IOperationBehavior.AddBindingParameters member
        //
        public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
        {
        }

        //
        // IOperationBehavior.ApplyClientBehavior member
        //
        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {
            clientOperation.Parent.MessageInspectors.Add(new I18nMessageInspector (locale, timezone));
        }

        //
        // IOperationBehavior.ApplyDispatchBehavior member
        //
        public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
            dispatchOperation.Parent.MessageInspectors.Add(new I18nMessageInspector(null,null));
        }

        //
        // IOperationBehavior.Validate member
        //
        public void Validate(OperationDescription operationDescription)
        {
        }

        private string _locale;
        private string _timezone;
    }

}
